package com.example.shushiyunsst.fragment.main.home.child.new_sale.recycler.provider

import android.content.Context
import android.view.View
import com.example.library_common.adapter.multi.JssMultiItemEntity
import com.example.library_common.adapter.multi.JssMultiItemViewHolder
import com.example.library_common.adapter.multi.JssNewMultipleAdapter
import com.example.library_common.album.view.grid_view.XGridLayout
import com.example.library_common.album.view.grid_view.adapter.CommAdapter
import com.example.library_common.album.view.grid_view.adapter.XQuickViewHolder
import com.example.shushiyunsst.R
import com.example.shushiyunsst.fragment.main.home.child.new_sale.recycler.bean.NewSaleCurrencyEntity
import com.example.shushiyunsst.fragment.main.home.child.new_sale.recycler.bean.NewSaleCurrencyWrapperEntity
import com.example.shushiyunsst.fragment.main.home.child.new_sale.recycler.bean.NewSaleEntity
import com.example.shushiyunsst.fragment.main.home.child.new_sale.recycler.bean.NewSaleMineEntity
import com.example.shushiyunsst.fragment.main.home.recycler.bean.CurrencyEntity

class NewSaleCurrencyProvider(view: View?)
    : JssMultiItemViewHolder<NewSaleCurrencyWrapperEntity>(view) {

    private var mAdapter: CommAdapter<NewSaleCurrencyEntity>? = null

    override fun getItemLayout(): Int {
        return R.layout.new_sale_currency_provider
    }

    override fun convert(context: Context?, m: NewSaleCurrencyWrapperEntity?) {
        super.convert(context, m)
        val mLineLayout: XGridLayout = findView22 (R.id.mLineLayout)
        if (mAdapter == null) {
            mAdapter = object : CommAdapter<NewSaleCurrencyEntity>(
                context,
                R.layout.new_sale_currency_provider_item_layout
            ) {
                override fun convert(
                    holder: XQuickViewHolder,
                    item: NewSaleCurrencyEntity,
                    position: Int
                ) {


                    holder.displayImage(R.id.mImageView,item.modUrl)
                        .setOnClickListener (
                            R.id.mImageView
                        ) {
                            if (adapter is JssNewMultipleAdapter<*>) {
                                val itemViewClick =
                                    (adapter as JssNewMultipleAdapter<JssMultiItemEntity>)
                                        .adapterViewItemViewClick
                                itemViewClick?.onAdapterViewListItemViewClick(
                                    item as JssMultiItemEntity,
                                    NewSaleEntity.NEW_SALE_CURRENCY_TYPE
                                )
                            }
                        }
                }
            }
        }
        if (adapter is JssNewMultipleAdapter<*>) {
            mLineLayout.setAdapter(mAdapter, (adapter as JssNewMultipleAdapter<*>).lifecycle)
        }

        mAdapter?.clear()
        mAdapter?.addAll( m?.getData() as MutableList<NewSaleCurrencyEntity>)
        mLineLayout.maxItem =mAdapter?.count?:1
    }

}